﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Kiosk
{
    public partial class frmFiyatgor : Form
    {
        public frmFiyatgor()
        {
            InitializeComponent();
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtBarkod.Text))
            {
                this.Close();
            }
        }

        private void frmFiyatgor_Activated(object sender, EventArgs e)
        {
            txtBarkod.Focus();
        }

        private void txtBarkod_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                pictureEdit1.Visible = false;
                lbl1.Visible = true;
                lbl2.Visible = true;
                lbl3.Visible = true;
                lblUrunAdi.Visible = true;
                lblKartFiyati.Visible = true;
                lblFiyati.Visible = true;

                Urun urn = Database.Get.Find(txtBarkod.Text);
                if (urn != null)
                {
                    lblUrunAdi.Text = urn.UrunAdi;
                    lblFiyati.Text = urn.Fiyati.ToString() + " TL";
                    Toptan top = urn.Fiyatlar.Where(x => x.FiyatNo == 3).FirstOrDefault();
                    if (top != null)
                    {
                        lblKartFiyati.Text = top.Fiyat.ToString() + " TL";
                    }
                }
                else
                {
                    lblUrunAdi.Text = "Ürün Bulunamadı !";
                    lblFiyati.Text = "";
                    lblKartFiyati.Text = "";
                }
                txtBarkod.Text = "";
                txtBarkod.Focus();
            }
        }

        private void frmFiyatgor_Load(object sender, EventArgs e)
        {
            frmMain own = this.Owner as frmMain;
            own.FiyatGorAktif = true;
        }

        private void frmFiyatgor_FormClosed(object sender, FormClosedEventArgs e)
        {
            frmMain own = this.Owner as frmMain;
            own.FiyatGorAktif = false;
        }

        private void timer2_Tick(object sender, EventArgs e)
        {
            txtBarkod.Focus();
        }
    }
}
